package com.yunhoo.sys.db.config;

import com.ibatis.common.resources.Resources;
import com.ibatis.dao.client.DaoManager;
import com.ibatis.dao.client.DaoManagerBuilder;
import com.yunhoo.base.db.dao.AssetGBCodeDao;
import java.io.Reader;
import java.sql.SQLException;
import java.util.Properties;

/**
 *
 * @author Administrator
 */
public class DaoConfig {

    private static final String resource = "com/yunhoo/sys/db/config/dao.xml";
    private static DaoManager daoManager;

    static {
        daoManager = newDaoManager(null);
    }

    public static DaoManager getDaoManager() {
        return daoManager;

    }

//    public static DaoManager getDaoManager(String dbname) {
//        if (dbname.equals("jdbc/managesys")) {
//            daoManager = newDaoManager(null);
//        } else if (dbname.equals("jdbc/mherpdb")) {
//            daoManager = newDaoManager1(null);
//        } else if (dbname.equals("jdbc/jserpdb")) {
//            daoManager = newDaoManager2(null);
//        }
//        return daoManager;
//    }
    public static DaoManager newDaoManager(Properties props) {
        try {
            Reader reader = Resources.getResourceAsReader(resource);
            return DaoManagerBuilder.buildDaoManager(reader, props);
        } catch (Exception e) {
            throw new RuntimeException("Could not initialize DaoConfig.  Cause: " + e, e);
        }
    }
    
    
    public static void main(String args[]) throws SQLException{
        AssetGBCodeDao deptDao = (AssetGBCodeDao) daoManager.getDao(AssetGBCodeDao.class);
        System.out.println("deptDao : " + deptDao.queryAll());
    }
}
